﻿using System;

namespace ClewareWrapper
{
    internal class BlinkingLight
    {
        private AdvancedState _state;
        public AdvancedState State
        {
            get { return _state; }
            set
            {
                _state = value;
                SetFromState(value);
            }
        }

        public BlinkingLight(Action<bool> setter)
        {
            _setter = setter;
        }

        private bool _transientState;
        private readonly Action<bool> _setter;

        private void SetFromState(AdvancedState advancedState)
        {
            switch (advancedState)
            {
                case AdvancedState.On:
                    _setter(true);
                    break;
                case AdvancedState.Off:
                    _setter(false);
                    break;
            }
        }

        public void BlinkingTick()
        {
            if (State == AdvancedState.Blinking)
            {
                _transientState = !_transientState;
                _setter(_transientState);
            }
        }
    }
}
